/**
 * @文件名称: PublishTimer.java
 * @类路径:   com.dssrz.weibo4j.timer
 * @描述:     TODO
 * @作者:     robin
 * @时间:     2012-3-13 下午04:35:28
 * @版本:     1.0.0
 */
package com.dssrz.weibo4j.timer;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import com.dssrz.weibo4j.task.Task;


/**
 * @类功能说明: 定时任务
 * @类修改者:     
 * @修改日期:   
 * @修改说明:   
 * @作者:       robin
 * @创建时间:   2012-3-13 下午04:35:28
 * @版本:       1.0.0
 */

public class PublishTimer {

	public static Task currentTask;
	public static Timer timer = new Timer();
	public static TimerTask timerTask = new PublishTimerTask(currentTask);
	
	/**
	 * @方法说明: 
	 * @参数:     @param task
	 * @return    void
	 * @throws
	 */
	public static void checkTask(Task task) {
		Date excuteTime = task.getBeginExceuteTime();
		Date now = new Date();
		long delay = excuteTime.getTime() - now.getTime();
		if(null == currentTask || excuteTime.before(currentTask.getBeginExceuteTime())) {
			currentTask = task;
			timer.cancel();
			if(delay > 0) {
				timer.schedule(timerTask, delay);
			} else {
				timer.schedule(timerTask, 0);
			}
		}
	}

}
